<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="标准端编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-equipment"
						v-decorator="['standardNo', validatorRules.standardNo]"
						:trigger-change="true"
						org-fields="id,standard_no,standard_name,standard_version,standard_sn,mcode"
						dest-fields="standard_id,standard_no,standard_name,standard_version,standard_sn,standard_mcode"
						code="mes_get_standard_calibrationrecord"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'standardName', validatorRules.standardName]" placeholder="请输入标准端名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'standardDescription', validatorRules.standardDescription]" placeholder="请输入标准端描述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'standardSn', validatorRules.standardSn]" placeholder="请输入标准端SN"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'standardMcode', validatorRules.standardMcode]" placeholder="请输入标准端产品编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端版次" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'standardVersion', validatorRules.standardVersion]" placeholder="请输入标准端版次"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'standardSprc', validatorRules.standardSprc]" placeholder="请输入型号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="复核期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择复核期" v-decorator="[ 'reviewdt', validatorRules.reviewdt]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="有效期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择有效期" v-decorator="[ 'validdt', validatorRules.validdt]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品系列" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mseries', validatorRules.mseries]" placeholder="请输入产品系列"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端模板名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-equipment"
						v-decorator="['standardTemplateName', validatorRules.standardTemplateName]"
						:trigger-change="true"
						org-fields="id,standard_template_no,standard_template_name,template_version"
						dest-fields="standard_template_id,standard_template_no,standard_template_name,standard_template_version"
						code="mes_get_standard_template"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标准端模板版次" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'standardTemplateVersion', validatorRules.standardTemplateVersion]" placeholder="请输入标准端模板版次"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="发行时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择发行时间" v-decorator="[ 'issuedt', validatorRules.issuedt]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="审核" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['checkflg', validatorRules.checkflg]" :trigger-change="true" dictCode="mes_checkflg" placeholder="请选择审核"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-switch  placeholder="String" v-decorator="['status']" field="status" dictCode="valid_status" @callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import fSwitch from '@/components/switch'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesEqStandardAccountModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JDictSelectTag,
      fSwitch,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        standardNo:{rules: [{ required: true, message: '请输入标准端编码!' }]},
        standardName:{},
        standardDescription:{},
        standardSn:{},
        standardMcode:{},
        standardVersion:{},
        standardSprc:{},
        reviewdt:{rules: [{ required: true, message: '请输入复核期!' }]},
        validdt:{rules: [{ required: true, message: '请输入有效期!' }]},
        mseries:{rules: [{ required: true, message: '请输入产品系列!' }]},
        standardTemplateName:{},
        standardTemplateVersion:{},
        issuedt:{rules: [{ required: true, message: '请输入发行时间!' }]},
        checkflg:{rules: [{ required: true, message: '请输入审核!' }]},
        status:{rules: [{ required: true, message: '请输入状态!' }]},
        remark:{},
        },
        url: {
          add: '/mes-equipment/auto/mesEqStandardAccount/add',
          edit: '/mes-equipment/auto/mesEqStandardAccount/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'standardNo','standardName','standardDescription','standardSn','standardMcode','standardVersion','standardSprc','reviewdt','validdt','mseries','standardTemplateName','standardTemplateVersion','issuedt','checkflg','status','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'standardNo','standardName','standardDescription','standardSn','standardMcode','standardVersion','standardSprc','reviewdt','validdt','mseries','standardTemplateName','standardTemplateVersion','issuedt','checkflg','status','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>